package client_controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;

import javax.swing.DefaultListModel;

import server_gui.ServerLog;
import client_controllers.DefineCategoryController.Back;
import client_gui.CustomerReportsGUI;
import client_logic.CcrmClient;
import client_logic.dbHandler;
import entity.Boss;


public class CustomerReportsController implements dbHandler{

	private CustomerReportsGUI crg;
	private MarketingManagerController mmc;
	private EmployeeLoginController elc;
	private Boss b=new Boss(null,null,null);

	
	public CustomerReportsController(CustomerReportsGUI crg,EmployeeLoginController elc, MarketingManagerController mmc) {
		   this.crg=crg;
		   this.mmc=mmc;
		   this.crg.getBtnBack().addActionListener(new Back());
		   this.b.setCommand("getCustomerReports");
		   this.b.setControl("CustomerReportsController");
		   update();
	}

	
	public class Back implements ActionListener{
		public void actionPerformed(ActionEvent e) {
		getCrg().dispose();
		mmc.getMmg().setVisible(true);
		}
	}

	public CustomerReportsGUI getCrg() {
		return crg;
	}


	public void setCrg(CustomerReportsGUI crg) {
		this.crg = crg;
	}

	
	public MarketingManagerController getMmc() {
		return mmc;
	}


	public void setMmc(MarketingManagerController mmc) {
		this.mmc = mmc;
	}


	public EmployeeLoginController getElc() {
		return elc;
	}


	public void setElc(EmployeeLoginController elc) {
		this.elc = elc;
	}


	public Boss getB() {
		return b;
	}


	public void setB(Boss b) {
		this.b = b;
	}


	@Override
	public void Add() {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void Search() {
		try {
			CcrmClient.inet.setCurrCon(this);
			CcrmClient.inet.sendToServer(b);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}


	@Override
	public String Delete() {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public void HandleMsg(Object msg) {	
		this.setB((Boss) msg);
		ArrayList<String> customer = (ArrayList<String>) b.getObj();

	for(String i: customer )
		crg.log.addElement(i);
		//ServerLog.log.addElement(new Date().toString()+"Client " +client.getInetAddress() + " connected");
		
	}


	@Override
	public void update() {
		try {
			CcrmClient.inet.setCurrCon(this);
			CcrmClient.inet.sendToServer(b);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	
	

}
